/**
 *
 * Copyright 2008 davethedev@googlemail.com
 *
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package nethelp.gui;

import javax.naming.NamingException;
import nethelp.network.MXLookup;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import nethelp.gui.utils.SwingWorker;
import nethelp.network.NetworkInterfaceTableModel;
import nethelp.network.handler.TraceRouteHandler;

public class MainFrame extends javax.swing.JFrame {

    SwingWorker worker;

    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        logoPanel = new javax.swing.JPanel();
        imageLabel = new javax.swing.JLabel(new ImageIcon(getClass().getResource("logo.png")));
        tabPane = new javax.swing.JTabbedPane();
        informationTab = new javax.swing.JPanel();
        lblHostName = new javax.swing.JLabel();
        hostName = new javax.swing.JLabel();
        lblIPAddress = new javax.swing.JLabel();
        ipAddress = new javax.swing.JLabel();
        lblOperatingSystem = new javax.swing.JLabel();
        operatingSystem = new javax.swing.JLabel();
        lblUserName = new javax.swing.JLabel();
        userName = new javax.swing.JLabel();
        networkTab = new javax.swing.JPanel();
        networkTableScrollPane = new javax.swing.JScrollPane();
        networkTable = new javax.swing.JTable();
        btnRefresh = new javax.swing.JButton();
        lookupTab = new javax.swing.JPanel();
        lblLookupIPAddress = new javax.swing.JLabel();
        lookupIPAddress = new javax.swing.JTextField();
        btnIPLookup = new javax.swing.JButton();
        lblLookupIPHostName = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblLookupHostIPAddress = new javax.swing.JLabel();
        lookupHostName = new javax.swing.JTextField();
        btnHostLookup = new javax.swing.JButton();
        mXTab = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        mXHostName = new javax.swing.JTextField();
        btnMXLookup = new javax.swing.JButton();
        lblMXCount = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        mXTable = new javax.swing.JTable();
        traceRouteTab = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        traceHost = new javax.swing.JTextField();
        btnTrace = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        traceResults = new javax.swing.JTextArea();
        aboutTab = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));

        logoPanel.setBackground(new java.awt.Color(255, 255, 255));
        logoPanel.setLayout(new java.awt.BorderLayout());

        imageLabel.setBackground(new java.awt.Color(255, 255, 255));
        logoPanel.add(imageLabel, java.awt.BorderLayout.CENTER);

        tabPane.setBackground(new java.awt.Color(255, 255, 255));

        informationTab.setBackground(new java.awt.Color(255, 255, 255));

        lblHostName.setText("Host name:");

        hostName.setText("...");

        lblIPAddress.setText("IP Address:");

        ipAddress.setText("...");

        lblOperatingSystem.setText("Operating System:");

        operatingSystem.setText("...");

        lblUserName.setText("User name:");

        userName.setText("...");

        org.jdesktop.layout.GroupLayout informationTabLayout = new org.jdesktop.layout.GroupLayout(informationTab);
        informationTab.setLayout(informationTabLayout);
        informationTabLayout.setHorizontalGroup(
            informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(informationTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(lblOperatingSystem, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 133, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lblUserName)
                    .add(lblIPAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                    .add(lblHostName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(ipAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .add(hostName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(operatingSystem, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(userName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        informationTabLayout.setVerticalGroup(
            informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(informationTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblHostName)
                    .add(hostName))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblIPAddress)
                    .add(ipAddress))
                .add(18, 18, 18)
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblOperatingSystem)
                    .add(operatingSystem))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblUserName)
                    .add(userName))
                .addContainerGap(280, Short.MAX_VALUE))
        );

        initializeInformationTab();

        tabPane.addTab("Information", informationTab);

        networkTable.setModel(new NetworkInterfaceTableModel());
        networkTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        networkTableScrollPane.setViewportView(networkTable);

        btnRefresh.setText("Refresh");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout networkTabLayout = new org.jdesktop.layout.GroupLayout(networkTab);
        networkTab.setLayout(networkTabLayout);
        networkTabLayout.setHorizontalGroup(
            networkTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(networkTableScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, networkTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(btnRefresh))
        );
        networkTabLayout.setVerticalGroup(
            networkTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(networkTabLayout.createSequentialGroup()
                .add(networkTableScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(btnRefresh))
        );

        tabPane.addTab("Network", networkTab);

        lblLookupIPAddress.setText("IP Address:");

        btnIPLookup.setText("Lookup");
        btnIPLookup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIPLookupActionPerformed(evt);
            }
        });

        lblLookupIPHostName.setText("...");

        jLabel4.setText("Host Name:");

        lblLookupHostIPAddress.setText("...");

        btnHostLookup.setText("Lookup");
        btnHostLookup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHostLookupActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout lookupTabLayout = new org.jdesktop.layout.GroupLayout(lookupTab);
        lookupTab.setLayout(lookupTabLayout);
        lookupTabLayout.setHorizontalGroup(
            lookupTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(lookupTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(lookupTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(lookupTabLayout.createSequentialGroup()
                        .add(lblLookupIPAddress)
                        .add(18, 18, 18)
                        .add(lookupTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(lblLookupIPHostName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
                            .add(lookupTabLayout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(lookupIPAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 153, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(18, 18, 18)
                                .add(btnIPLookup))
                            .add(lblLookupHostIPAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)))
                    .add(lookupTabLayout.createSequentialGroup()
                        .add(jLabel4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(lookupHostName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 152, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(btnHostLookup)))
                .addContainerGap())
        );
        lookupTabLayout.setVerticalGroup(
            lookupTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(lookupTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(lookupTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblLookupIPAddress)
                    .add(btnIPLookup)
                    .add(lookupIPAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(lblLookupIPHostName)
                .add(42, 42, 42)
                .add(lookupTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(lookupHostName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnHostLookup))
                .add(18, 18, 18)
                .add(lblLookupHostIPAddress)
                .addContainerGap(213, Short.MAX_VALUE))
        );

        tabPane.addTab("Lookup", lookupTab);

        jLabel5.setText("Host Name:");

        btnMXLookup.setText("Lookup");
        btnMXLookup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMXLookupActionPerformed(evt);
            }
        });

        lblMXCount.setText("...");

        mXTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(mXTable);

        org.jdesktop.layout.GroupLayout mXTabLayout = new org.jdesktop.layout.GroupLayout(mXTab);
        mXTab.setLayout(mXTabLayout);
        mXTabLayout.setHorizontalGroup(
            mXTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mXTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(mXTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(mXTabLayout.createSequentialGroup()
                        .add(jLabel5)
                        .add(18, 18, 18)
                        .add(mXHostName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btnMXLookup)
                        .add(87, 87, 87))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, mXTabLayout.createSequentialGroup()
                        .add(mXTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, lblMXCount, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE))
                        .addContainerGap())))
        );
        mXTabLayout.setVerticalGroup(
            mXTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mXTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(mXTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(btnMXLookup)
                    .add(mXHostName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(34, 34, 34)
                .add(lblMXCount)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabPane.addTab("MX Lookup", mXTab);

        jLabel6.setText("Host:");

        btnTrace.setText("Trace");
        btnTrace.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTraceActionPerformed(evt);
            }
        });

        traceResults.setColumns(20);
        traceResults.setRows(5);
        jScrollPane2.setViewportView(traceResults);

        org.jdesktop.layout.GroupLayout traceRouteTabLayout = new org.jdesktop.layout.GroupLayout(traceRouteTab);
        traceRouteTab.setLayout(traceRouteTabLayout);
        traceRouteTabLayout.setHorizontalGroup(
            traceRouteTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(traceRouteTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(traceRouteTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
                    .add(traceRouteTabLayout.createSequentialGroup()
                        .add(jLabel6)
                        .add(18, 18, 18)
                        .add(traceHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 281, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(btnTrace)))
                .addContainerGap())
        );
        traceRouteTabLayout.setVerticalGroup(
            traceRouteTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(traceRouteTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(traceRouteTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(traceHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnTrace))
                .add(18, 18, 18)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabPane.addTab("Trace Route", traceRouteTab);

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 48));
        jLabel2.setForeground(new java.awt.Color(255, 0, 51));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("NetHelp");

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 204));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("version 0.2");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Developed by davethedev@googlemail.com 2008");

        org.jdesktop.layout.GroupLayout aboutTabLayout = new org.jdesktop.layout.GroupLayout(aboutTab);
        aboutTab.setLayout(aboutTabLayout);
        aboutTabLayout.setHorizontalGroup(
            aboutTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(aboutTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(aboutTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
                    .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
                    .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE))
                .addContainerGap())
        );
        aboutTabLayout.setVerticalGroup(
            aboutTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(aboutTabLayout.createSequentialGroup()
                .add(44, 44, 44)
                .add(jLabel2)
                .add(18, 18, 18)
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel3)
                .addContainerGap(237, Short.MAX_VALUE))
        );

        tabPane.addTab("About", aboutTab);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(logoPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(tabPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(logoPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .add(tabPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        networkTable.setModel(new NetworkInterfaceTableModel());
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void btnIPLookupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIPLookupActionPerformed
        try {
            InetAddress addr = InetAddress.getByName(lookupIPAddress.getText());
            lblLookupIPHostName.setText(addr.getHostName());
        } catch (UnknownHostException ex) {
            lblLookupIPHostName.setText("Host not found.");
        }

    }//GEN-LAST:event_btnIPLookupActionPerformed

    private void btnHostLookupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHostLookupActionPerformed
        StringBuffer fullIpAddress = new StringBuffer();
        try {
            InetAddress address = InetAddress.getByName(lookupHostName.getText());
            byte[] ipAddressBytes = address.getAddress();

            // Convert to dot representation
            for (int i = 0; i < ipAddressBytes.length; i++) {
                if (i > 0) {
                    fullIpAddress.append(".");
                }
                fullIpAddress.append(ipAddressBytes[i] & 0xFF);
            }
            lblLookupHostIPAddress.setText(fullIpAddress.toString());
        } catch (UnknownHostException ex) {
            lblLookupHostIPAddress.setText("Host not found.");
        }
    }//GEN-LAST:event_btnHostLookupActionPerformed

    private void btnMXLookupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMXLookupActionPerformed
        lblMXCount.setText("...");
        if (mXHostName.getText().length() > 0) {
            try {
                new MXLookup(mXHostName.getText(), lblMXCount, mXTable);
            } catch (NamingException ex) {
                JOptionPane.showMessageDialog(this, "The domain name could not be found.");
            }
        } else {
            JOptionPane.showMessageDialog(this, "Please enter a domain to check the MX record against.");
        }
    }//GEN-LAST:event_btnMXLookupActionPerformed

    private void btnTraceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTraceActionPerformed
        if (traceHost.getText().length()==0) {
            JOptionPane.showMessageDialog(this, "Please enter a domain to trace the route to.");
            return;
        }

        // If a trace is not already active...
        if (btnTrace.getText().equalsIgnoreCase("Trace")) {
            traceResults.setText("");

            worker = new SwingWorker() {

                @Override
                public Object construct() {
                    btnTrace.setText("Cancel");
                    return new TraceRouteHandler(traceResults, traceHost.getText());
                }

                @Override
                public void finished() {
                    btnTrace.setText("Trace");
                }
            };
            worker.start();
        } else {
            // A trace is already active...
            worker.interrupt();
            btnTrace.setText("Trace");
        }
    }//GEN-LAST:event_btnTraceActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            // Set the default platform l & f
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    private void initializeInformationTab() {
        try {
            InetAddress addr = InetAddress.getLocalHost();
            hostName.setText(addr.getHostName());
            ipAddress.setText(addr.getHostAddress());
        } catch (UnknownHostException e) {
            hostName.setText("<<unknown>>");
            ipAddress.setText("<<unknown>>");
        }

        String osName = System.getProperty("os.name");
        String osVersion = System.getProperty("os.version");
        operatingSystem.setText(osName + " " + osVersion);

        String un = System.getProperty("user.name");
        userName.setText(un);

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel aboutTab;
    private javax.swing.JButton btnHostLookup;
    private javax.swing.JButton btnIPLookup;
    private javax.swing.JButton btnMXLookup;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnTrace;
    private javax.swing.JLabel hostName;
    private javax.swing.JLabel imageLabel;
    private javax.swing.JPanel informationTab;
    private javax.swing.JLabel ipAddress;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblHostName;
    private javax.swing.JLabel lblIPAddress;
    private javax.swing.JLabel lblLookupHostIPAddress;
    private javax.swing.JLabel lblLookupIPAddress;
    private javax.swing.JLabel lblLookupIPHostName;
    private javax.swing.JLabel lblMXCount;
    private javax.swing.JLabel lblOperatingSystem;
    private javax.swing.JLabel lblUserName;
    private javax.swing.JPanel logoPanel;
    private javax.swing.JTextField lookupHostName;
    private javax.swing.JTextField lookupIPAddress;
    private javax.swing.JPanel lookupTab;
    private javax.swing.JTextField mXHostName;
    private javax.swing.JPanel mXTab;
    private javax.swing.JTable mXTable;
    private javax.swing.JPanel networkTab;
    private javax.swing.JTable networkTable;
    private javax.swing.JScrollPane networkTableScrollPane;
    private javax.swing.JLabel operatingSystem;
    private javax.swing.JTabbedPane tabPane;
    private javax.swing.JTextField traceHost;
    private javax.swing.JTextArea traceResults;
    private javax.swing.JPanel traceRouteTab;
    private javax.swing.JLabel userName;
    // End of variables declaration//GEN-END:variables
}
